<?php

namespace app\index\controller;

use app\index\service\TestService;
use app\index\validate\TestValidate;

/**
 * Test控制器
 * Class Test
 * @package app\index\controller
 */
class Test extends Controller
{

    /**
     * @notes 获取列表
     * @return \think\response\Json
     */
    public function lists()
    {
        $params = request()->get();
        $service = new TestService();
        $result = $service->getTestLists($params, $this->page);
        return $this->success($result);
    }


    /**
     * @notes 添加
     * @return \think\response\Json
     */
    public function add()
    {
        $params = $this->checkPost(TestValidate::class, 'add');
        $service = new TestService();
        $result = $service->addTest($params);
        if (false === $result) {
            return $this->fail($service->getError());
        }
        return $this->success('操作成功');
    }


    /**
     * @notes 编辑
     * @return \think\response\Json
     */
    public function edit()
    {
        $params = $this->checkPost(TestValidate::class, 'edit');
        $service = new TestService();
        $result = $service->editTest($params);
        if (false === $result) {
            return $this->fail($service->getError());
        }
        return $this->success('操作成功');
    }


    /**
     * @notes 获取详情
     * @return \think\response\Json
     */
    public function detail()
    {
        $params = $this->checkGet(TestValidate::class, 'id');
        $service = new TestService();
        $result = $service->getTestDetail($params['id']);
        return $this->success(compact('result'));
    }


    /**
     * @notes 删除
     * @return \think\response\Json
     */
    public function del()
    {
        $params = $this->checkPost(TestValidate::class, 'id');
        $service = new TestService();
        $service->delTest($params['id']);
        return $this->success('操作成功');
    }

}
